package com.woniuxy.java106crm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.java106crm.entity.LogManage;
import com.woniuxy.java106crm.entity.Lost;
import com.woniuxy.java106crm.mapper.LogManageMapper;
import com.woniuxy.java106crm.request.ResPage;
import com.woniuxy.java106crm.service.LogManageService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LogManageServiceImpl implements LogManageService {
    @Resource
    private LogManageMapper logManageMapper;

    @Override
    public void addLogManage(LogManage logManage) {
        logManageMapper.addLogManage(logManage);
    }

    @Override
    public ResPage<List<LogManage>> queryCondition(Integer page, Integer size, LogManage logManage) {
        PageHelper.startPage(page, size);
        List<LogManage> logManageList = logManageMapper.queryCondition(logManage);
        PageInfo<LogManage> info = new PageInfo<>(logManageList);
        ResPage<List<LogManage>> resPage = new ResPage<>();
        resPage.setSize(size);
        resPage.setCurPage(page);
        resPage.setTotal(info.getTotal());
        resPage.setData(logManageList);
        return resPage;
    }

    @Override
    public boolean deleteById(Integer id) {
        return logManageMapper.deleteById(id);
    }

    @Transactional
    @Override
    public boolean batchedDelByIds(String ids) {
        Boolean flag = false;
        //拆分字符串
        String[] idsData = ids.split(",");
        //遍历数组
        for(String id : idsData){
            //调用dao层方法：根据id 删除信息
            flag = logManageMapper.deleteById(Integer.valueOf(id));
        }
        return flag;
    }
}
